﻿using Excel2DbTool.Common;
using Excel2DbTool.Models;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

namespace Excel2DbTool.Helpers
{
	/**/
	public class ZRZTableMigrater : DbTableMigrater
	{
		static List<DbFieldMapping> dbFieldMappings = new List<DbFieldMapping>()
		{
			 //has match
			 new OracleTableStrField(OrginTableFieldNames.BUILDNO,SelfFieldNames.ZRZID), //KEY
			new OracleTableStrField(OrginTableFieldNames.PROADDR,SelfFieldNames.XMID),
			new OracleTableStrField(OrginTableFieldNames.PROJECTNAME,SelfFieldNames.XMMC),
			new OracleTableNumField(OrginTableFieldNames.FULLLAYER,SelfFieldNames.ZCS),
			//new OracleTableStrField(OrginTableFieldNames.STRUCTURE,SelfFieldNames.FWJG),
			new OracleTableStrField(OrginTableFieldNames.USE,SelfFieldNames.JZWJBYT),

			//can not be null,but orgin table has no match；so we will not select relative data from orgin table;
			//but will give a default value to  target table
			new OracleTableStrField(OrginTableFieldNames.NONE,SelfFieldNames.JZWMC),
			new OracleTableNotNullNumField(OrginTableFieldNames.NONE,SelfFieldNames.ZT),
			new OracleTableStrField(OrginTableFieldNames.NONE,SelfFieldNames.ZRZH2),
		};

		public ZRZTableMigrater()
			: base(OrginTableFieldNames.BUILDNO,DbTableNames.BDC_ZRZ)
		{
		}

		protected override IList<DbFieldMapping> DbFieldMappings
		{
			get { return dbFieldMappings; }
		}

		class SelfFieldNames
		{
			internal static readonly string ZRZID = "ZRZID";
			internal static readonly string XMID = "XMID";
			internal static readonly string BDCDYH = "BDCDYH";
			internal static readonly string ZDDM = "ZDDM";
			internal static readonly string ZRZH = "ZRZH";
			internal static readonly string XMMC = "XMMC";
			internal static readonly string JZWMC = "JZWMC";
			internal static readonly string JGRQ = "JGRQ";
			internal static readonly string GJWGD = "GJWGD";
			internal static readonly string ZZDMJ = "ZZDMJ";
			internal static readonly string ZYDMJ = "ZYDMJ";
			internal static readonly string YCJZMJ = "YCJZMJ";
			internal static readonly string SCJZMJ = "SCJZMJ";
			internal static readonly string ZCS = "ZCS";
			internal static readonly string DSCS = "DSCS";
			internal static readonly string DXCS = "DXCS";
			internal static readonly string DXSD = "DXSD";
			internal static readonly string GHYT = "GHYT";
			internal static readonly string FWJG = "FWJG";
			internal static readonly string ZTS = "ZTS";
			internal static readonly string JZWJBYT = "JZWJBYT";
			internal static readonly string BZ = "BZ";
			internal static readonly string X = "X";
			internal static readonly string Y = "Y";
			internal static readonly string ZT = "ZT";
			internal static readonly string CJSJ = "CJSJ";
			internal static readonly string CJR = "CJR";
			internal static readonly string XGSJ = "XGSJ";
			internal static readonly string XGR = "XGR";
			internal static readonly string ZRZH2 = "ZRZH2";
		}
	}


	/*
	   -- Create table
	create table BDC_ZRZ
	(
	  zrzid   VARCHAR2(36) not null,
	  xmid    VARCHAR2(36),
	  bdcdyh  VARCHAR2(28),
	  zddm    VARCHAR2(19),
	  zrzh    VARCHAR2(20),
	  xmmc    VARCHAR2(100),
	  jzwmc   VARCHAR2(100) not null,
	  jgrq    DATE,
	  gjwgd   FLOAT,
	  zzdmj   FLOAT,
	  zydmj   FLOAT,
	  ycjzmj  FLOAT,
	  scjzmj  FLOAT,
	  zcs     INTEGER,
	  dscs    INTEGER,
	  dxcs    INTEGER,
	  dxsd    FLOAT,
	  ghyt    VARCHAR2(4),
	  fwjg    VARCHAR2(2),
	  zts     INTEGER,
	  jzwjbyt VARCHAR2(200),
	  bz      VARCHAR2(1000),
	  x       NUMBER,
	  y       NUMBER,
	  zt      NUMBER default 1 not null,
	  cjsj    DATE,
	  cjr     VARCHAR2(50),
	  xgsj    DATE,
	  xgr     VARCHAR2(50),
	  zrzh2   VARCHAR2(20) not null
	)
	tablespace BDCDJ0616
	  pctfree 10
	  initrans 1
	  maxtrans 255
	  storage
	  (
		initial 128K
		next 8K
		minextents 1
		maxextents unlimited
	  );
	-- Add comments to the columns 
	comment on column BDC_ZRZ.zrzid
	  is '自然幢ID';
	comment on column BDC_ZRZ.xmid
	  is '项目ID';
	comment on column BDC_ZRZ.bdcdyh
	  is '不动产单元号';
	comment on column BDC_ZRZ.zddm
	  is '宗地代码';
	comment on column BDC_ZRZ.zrzh
	  is '自然幢顺序号';
	comment on column BDC_ZRZ.xmmc
	  is '项目名称';
	comment on column BDC_ZRZ.jzwmc
	  is '建筑物名称';
	comment on column BDC_ZRZ.jgrq
	  is '竣工日期';
	comment on column BDC_ZRZ.gjwgd
	  is '建筑物高度';
	comment on column BDC_ZRZ.zzdmj
	  is '幢占地面积';
	comment on column BDC_ZRZ.zydmj
	  is '幢用地面积';
	comment on column BDC_ZRZ.ycjzmj
	  is '预测建筑面积';
	comment on column BDC_ZRZ.scjzmj
	  is '实测建筑面积';
	comment on column BDC_ZRZ.zcs
	  is '总层数';
	comment on column BDC_ZRZ.dscs
	  is '地上层数';
	comment on column BDC_ZRZ.dxcs
	  is '地下层数';
	comment on column BDC_ZRZ.dxsd
	  is '地下深度';
	comment on column BDC_ZRZ.ghyt
	  is '规划用途';
	comment on column BDC_ZRZ.fwjg
	  is '房屋结构';
	comment on column BDC_ZRZ.zts
	  is '总套数';
	comment on column BDC_ZRZ.jzwjbyt
	  is '建筑物基本用途';
	comment on column BDC_ZRZ.bz
	  is '备注';
	comment on column BDC_ZRZ.x
	  is 'X坐标';
	comment on column BDC_ZRZ.y
	  is 'Y坐标';
	comment on column BDC_ZRZ.zt
	  is '状态';
	comment on column BDC_ZRZ.cjsj
	  is '创建时间';
	comment on column BDC_ZRZ.cjr
	  is '创建人';
	comment on column BDC_ZRZ.xgsj
	  is '修改时间';
	comment on column BDC_ZRZ.xgr
	  is '修改人';
	comment on column BDC_ZRZ.zrzh2
	  is '自然幢号';
	-- Create/Recreate primary, unique and foreign key constraints 
	alter table BDC_ZRZ
	  add constraint N_BDC_ZRZ_ZRZID_PRI primary key (ZRZID)
	  using index 
	  tablespace BDCDJ0616
	  pctfree 10
	  initrans 2
	  maxtrans 255
	  storage
	  (
		initial 64K
		next 1M
		minextents 1
		maxextents unlimited
	  );

 
	 */
}
